/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.srcptit.trainning.huongpq.btvn1;

/**
 *
 * @author Admin_Pro
 */
public class Ham {
    public static boolean kTraNto(long n){
        if(n<=1||(n%2==0&&n!=2)) return false;
        long i;
        double m = Math.sqrt(n);
        for(i=3;i<=m;i+=2) if(n%i==0) return false;
        return true;
    }
    public static long ucln(long a, long b){
        while(a*b!=0){
            if(a>b) a = a % b;
            else b = b % a;
        }
        return(a+b);
    }
    public static long tong(long n){
        long t=0;
        while(n!=0){
            t += n%10;
            n/=10;
        }
        return t;
    }
    public static boolean ktFibo(long i){
        long f,f0 = 0,f1 = 1;
        long n = tong(i);
        while(true){
            f = f1+f0;
            f0 = f1;
            f1 = f;
            if(n==f) return true;
            else if(f>n) return false;            
        }
    }
    public static boolean ktThuanNghich(long n){
        long t=0,m=n;
        while(n!=0){
            t*=10;
            t+=n%10;
            n/=10;
        }
        return t==m;
    }
    public static boolean ktraPhanTu(long n){
        long t;
        while(n!=0){
            t = n%10;
            n/=10;
            if(t!=2&&t!=3&&t!=5&&t!=7) return false;
        }
        return true;
    }
    public static boolean ktraDay(long n){
        long[] a;
        a = new long[8];
        for(int i=0;i<7;i++){
            a[i] = n % 10;
            n/=10; 
        }
        for(int i=0;i<6;i++){
            if(a[i]>a[i+1]) return false;
        }
        return true;
    }
}
